home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9349 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  122 lines

  1. Path: alpha2.csd.uwm.edu!peterk
  2. From: peterk@alpha2.csd.uwm.edu (Peter J Kleczka)
  3. Newsgroups: comp.lang.c
  4. Subject: Crash Proofing?
  5. Date: 9 Mar 1996 17:36:46 GMT
  6. Organization: Information & Media Technologies, University of Wisconsin - Milwaukee
  7. Distribution: world
  8. Message-ID: <4hsfje$rbr@uwm.edu>
  9. NNTP-Posting-Host: 129.89.169.2
  10.  
  11. Hi all
  12.     I'm new to C programing and am trying to re-write a program
  13. I did in pascal in C.  When I wrote the pascal program I got
  14. caught up in the details of getting the program to work and
  15. consequentially readability of the code and user-friendlyness
  16. suffered......
  17.  
  18.     The program I'm working on (below) works fine as long
  19. as the user enters an integer.....but it gets caught in an
  20. endless loop between the functions: firstmenu() and firstchoice()
  21. when I enter, say, 5.5 instead of an integer
  22.  
  23. it's unlikely that the user would enter anything but an integer
  24. when presented with integer choices...but I want to make the
  25. code uncrashable .....what can I do if anything to make it
  26. so that the program doesnt do wierd things if the user enters
  27. the wrong thing here?
  28.  
  29. thanks in advance
  30. (please email peterk@csd.uwm.edu) with your suggestions
  31. :)
  32.  
  33. /* prototype for the C version of block schedule program */
  34.  
  35. #include <stdio.h>
  36.  
  37. main(){
  38.  
  39. firstmenu(); /* call to programs main menu */
  40. firstchoice(); /* call to function which gets users choice from main menu */
  41.  
  42. } /* end main */
  43.  
  44. firstmenu(){ /* list users options */
  45.  
  46. printf ("\t\t\t *** M A I N   M E N U ***\n\n");
  47. printf ("Please choose one of the following:\n");
  48. printf ("\t1. Instructions\n");
  49. printf ("\t2. Enter a new schedule\n");
  50. printf ("\t3. Edit or Review schedule\n");
  51. printf ("\t4. Quit\n\n");
  52.  
  53. } /* end firstmenu */
  54.  
  55. firstchoice(){ /* get users choice and branch to appropos function */
  56.  
  57. unsigned choice;
  58.  
  59. scanf ("%d", &choice);
  60.                         /* while loop till user enters integer 1-4 */
  61. while (choice !=1 && choice != 2 && choice != 3 && choice !=4){
  62.   printf("You entered %d ... please choose a number between 1-4\n\n", choice);
  63.   firstmenu(); /* remind user of appropos choices */
  64.   scanf("%d", &choice);
  65. } /* end while */
  66.  
  67. switch (choice){
  68.  case 1: Instructions(); /* branch to instructions function */
  69.  
  70.    break;
  71.  
  72.  case 2: Entersch(); /* branch to enter schedule function */
  73.  
  74.    break;
  75.  
  76.  case 3: Editsch(); /* branch to edit schedule function */
  77.  
  78.    break;
  79.  
  80.  case 4: Goodbye(); /* branch to goodbye function */
  81.  
  82.    break;
  83.  
  84.  default: printf (" Error trap in firstchoice function, choice not 1-4\n");
  85.  
  86.    break;
  87.  
  88. }/* end switch */
  89. }/* end firstchoice */
  90.  
  91. Instructions(){ /* give user instructions on how to use this program */
  92.  
  93. printf ("\n\n\tCool instructions are comming soon\n\n");
  94. firstmenu(); /* remind user of choices again */
  95. firstchoice(); /* let user make another choice */
  96.  
  97. } /* end Instructions */
  98.  
  99. Entersch(){ /* let user enter a schedule */
  100.  
  101. printf("\n\n\tSoon youll be able to enter schedules\n\n");
  102. firstmenu(); /* remind user of choices again */
  103. firstchoice(); /* let user make another choice */
  104.  
  105. } /* end Entersch */
  106.  
  107. Editsch(){ /* let user edit schedules */
  108.  
  109. printf("\n\n\tSoon youll be able to edit schedules\n\n");
  110. firstmenu(); /* remind user of choices again */
  111. firstchoice(); /* let user make another choice */
  112.  
  113. } /* endit Editsch */
  114.  
  115. Goodbye(){ /* tell user the program has ended */
  116.  
  117. printf("\n\n\tBye now, ya all come back now hear\n\n");
  118.  
  119. } /* end Goodbye */
  120.  
  121.  
  122.